<!DOCTYPE html>
<!--
  ~ Copyright (c) 2018.
  ~ This file was written by fancyears·milos·malvis @connor. Any question/bug you can post to 1243093366@qq.com.
  ~ ALL RIGHTS RESERVED.
  -->
<!--二阶段特性从配置字典中获取-->
<html xmlns:th="http://www.thymeleaf.org"
      xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity4">
<link th:href="@{/css/labelColor.css}" rel="stylesheet">
<head>
    <meta charset="UTF-8">
    <title>添加特性</title>
</head>
<body>
<form id="featureForm" role="form" method="post" action="./cfg0/add2">
    <input class="form-control" id="pCfg0MainItemPuid" name="pCfg0MainItemPuid" type="hidden"
           th:value="${entity.puid}"/>
    <div class="form-group">
        <label for="pCfg0FamilyName">特性名称<span style="color: red">*</span></label>
        <input class="form-control" id="pCfg0FamilyName" name="pCfg0FamilyName" type="text"
               readonly="readonly"
        />
    </div>
    <div class="form-group">
        <label for="pCfg0FamilyDesc">特性描述<span style="color: red">*</span></label>
        <input class="form-control" id="pCfg0FamilyDesc" name="pCfg0FamilyDesc" type="text"
               readonly="readonly"
        />
        <!--disabled="disabled"-->
    </div>
    <div class="form-group">
        <label for="pH9featureenname">特性英文名称</label>
        <input class="form-control" id="pH9featureenname" name="pH9featureenname" type="text"
               readonly="readonly"
        />
    </div>
    </div>
    <div class="form-group">
        <label for="pCfg0ObjectId">特性值/配置代码<span style="color: red">*</span></label>
        <input class="form-control" id="pCfg0ObjectId" name="pCfg0ObjectId" type="text" onblur="returnCfgMsg(this)"
               placeholder="请输入特性值/配置代码"/>
        <div id="cfgFlag" style="color:#a94442;display: none">配置代码无效</div>
    </div>
    <div class="form-group">
        <label for="pCfg0Desc">特性值/配置(描述)<span style="color: red">*</span></label>
        <input class="form-control" id="pCfg0Desc" name="pCfg0Desc" type="text"
               readonly="readonly"/>
    </div>
    <!--<div class="form-group">-->
    <!--<label for="length">字符长度</label>-->
    <!--<input class="form-control" id="length" name="length" type="text" value="10"-->
    <!--placeholder="请输入字符长度"/>-->
    <!--</div>-->
</form>
<script th:inline="javascript">
    <![CDATA[
    $(document).keydown(function (event) {
        if (event.keyCode == 13) {
            $('form').each(function () {
                event.preventDefault();
            });
        }
    });
    $(function () {
        $('#featureForm').bootstrapValidator({
            message: 'This value is not valid',
            feedbackIcons: {
                valid: 'glyphicon glyphicon-ok',
                invalid: 'glyphicon glyphicon-remove',
                validating: 'glyphicon glyphicon-refresh'
            },
            fields: {
                pCfg0FamilyName: {
                    message: '特性名称验证失败',
                    validators: {
                        notEmpty: {
                            message: '特性名称不能为空'
                        },
                        //正则校验
                        regexp: {
                            regexp: /^[a-zA-Z][a-zA-Z0-9]*$/, /* ^ 指的是匹配字符串开始的位置 + 匹配一个或者多个*/
                            message: '特性只能以英文开头，加英文和数字，不允许有英文和数字以外的字符'
                        },
                        stringLength: {
                            max: 30,
                            message: '特性最长长度为30'
                        },
                    }
                },
                pCfg0FamilyDesc: {
                    message: '特性描述验证失败',
                    validators: {
                        notEmpty: {
                            message: '特性描述不能为空'
                        }
                    }
                },
                // pCfg0ObjectId: {
                //     message: '特性值/配置代码验证失败',
                //     validators: {
                //         notEmpty: {
                //             message: '特性值/配置代码不能为空'
                //         },
                //         //正则校验
                //         regexp: {
                //             regexp: /[a-zA-Z0-9]+$/, /* ^ 指的是匹配字符串开始的位置 + 匹配一个或者多个*/
                //             message: '特性值只能以数字/英文开头，加英文和数字，不允许有英文和数字以外的字符'
                //         },
                //         stringLength: {
                //             max: 10,
                //             message: '特性值最长长度为10'
                //         },
                //     }
                // },
                pCfg0Desc: {
                    message: '特性值/配置(描述)验证失败',
                    validators: {
                        notEmpty: {
                            message: '特性值/配置(描述)不能为空'
                        }
                    }
                },
                length: {
                    message: '字符长度验证失败',
                    validators: {
                        digits: {
                            message: '长度只能是整数'
                        }
                    }
                },
            }
        });
        // 绑定dialog的确定按钮的监听事件
        $("#btnOk", window.top.document).click(function () {
            var url = $("#featureForm", window.top.document).attr('action');
            var bootstrapValidator = $("#featureForm", window.top.document).data('bootstrapValidator');
            bootstrapValidator.validate();
            if (bootstrapValidator.isValid()) {
                // window.Ewin.confirm({
                //     title: '提示',
                //     message: '需要将特性<span style="color: #ac4e44">' + $("#pCfg0ObjectId").val() + '</span>自动发送到ERP',
                //     width: 500
                // }).on(function (e) {
                //     if (e) {
                //         //自动发送到ERP
                //         url += '?send=1';
                //     }
                //     else {
                //         url += '?send=0';
                //     }
                // });
                <!--其实不要puid，puid会在服务器上生成-->
                var myData = JSON.stringify({
                    "pCfg0FamilyName": $("#pCfg0FamilyName").val(),
                    "pCfg0FamilyDesc": $("#pCfg0FamilyDesc").val(),
                    "pCfg0ObjectId": $("#pCfg0ObjectId").val(),
                    "pCfg0Desc": $("#pCfg0Desc").val(),
                    "pH9featureenname": $("#pH9featureenname").val(),
                    "length": $("#length").val(),
                    "pCfg0MainItemPuid": $("#pCfg0MainItemPuid").val()
                });
                $.ajax({
                    contentType:
                        "application/json",
                    type:
                        'POST',
                    url: url,
                    success:
                        function (result) {
                            // $('.modal-dialog', window.top.document).parent('div').remove()
                            // $('body', window.top.document).find('.modal-backdrop').remove();
                            // jquery 调用刷新当前操作的table页面的refresh方法
                            // $(window.parent.document).contents().find(".tab-pane.fade.active.in iframe")[0].contentWindow.doQuery();
                            activeTabBodyRefresh();
                            if (result.status) {
                                layer.msg(result.msg, {icon: 1, time: 2000})
                            }
                            else {
                                window.Ewin.alert({message: result.msg});
                            }
                        },
                    data: myData,
                    error: function (status) {
                        window.Ewin.alert({message: status.status + ':添加数据失败!'});
                    }
                });
            }
        });
    })
    ]]>
</script>
<script>
    function returnCfgMsg(obj) {
        var cfgVal = $(obj).val();
        $.ajax({
            type: "GET",
            url: "./cfg0/returnCfgMsg?cfgVal=" + cfgVal,
            success: function (result) {
                if (result.stage) {
                    var libraryJson = result.data;
                    $(pCfg0FamilyName).val(libraryJson.famillyCode);
                    $(pCfg0FamilyDesc).val(libraryJson.famillyCh);
                    $("#pH9featureenname").val(libraryJson.famillyEn);
                    $("#pCfg0Desc").val(libraryJson.valueDescCh);
                    $("#cfgFlag").hide();
                }
                else {
                    $("#cfgFlag").show();
                }
            },
            error: function (result) {

            }
        });
    }
</script>
<script th:src="@{/layer/layer.js}"></script>
</body>
</html>